﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Weblications.Sango.Protocol.officer;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Formular;
using Pixysoft.Weblications.Sango.Environment;

namespace Pixysoft.Weblications.Sango.Protocol
{
    class OfficerFacade
    {
        public static List<player_officer> ToOfficers(List<Entities.Usr_Officer> orms)
        {
            List<player_officer> list = new List<player_officer>();

            foreach (Entities.Usr_Officer orm in orms)
            {
                list.Add(ToOfficer(orm));
            }

            return list;
        }

        public static player_officer ToOfficer(Entities.Usr_Officer orm)
        {
            player_officer entity = ReflectionManager.CreatePojo<player_officer>();

            Entities.Sys_Professional sysprof = SysProfessionalHelper.searchByCode(orm.Professionalserialcode);
            Entities.Sys_Officer sysofficer = SysOfficerHelper.searchBySerialcode(orm.Officerserialcode);

            entity.avatarid = sysofficer.Avatarcode;

            entity.primarycode = orm.Primarycode;
            entity.name = orm.Officername;
            entity.level = orm.Officerlevel;
            entity.exp = orm.Expvalue;
            entity.expmax = OfficerFormular.LevelupExperience(entity.level);

            entity.proftypecode = orm.Professionaltypecode;
            entity.profserialcode = orm.Professionalserialcode;
            entity.profname = sysprof.Professionalname;

            entity.skillname = sysofficer.Skilltypename;
            entity.skilltypecode = sysofficer.Skilltypecode;

            entity.currenthpvalue = orm.Currenthpvalue;
            entity.hpvalue = orm.Hpbasevalue + orm.Hpaddvalue;
            entity.forcevalue = orm.Forcebasevalue + orm.Forceaddvalue;
            entity.mindvalue = orm.Mindbasevalue + orm.Mindaddvalue;
            entity.directvalue = orm.Directbasevalue + orm.Directaddvalue;

            entity.hired = SettingHelper.BooleanValue(orm.Hired);
            entity.upgradestartdate = orm.Upgradestartdate;
            entity.upgradeenddate = orm.Upgradeenddate;
            entity.upgradespeedtypecode = orm.Upgradespeedtypecode;
            entity.upgradetimetypecode = orm.Upgradetimetypecode;

            entity.recuitprice = sysofficer.Recuitprice;

            return entity;
        }
    }
}
